package com.lemo;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.ui.ModelMap;
import org.springframework.web.context.request.WebRequest;
import org.springframework.web.context.request.WebRequestInterceptor;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
import org.springframework.web.servlet.handler.WebRequestHandlerInterceptorAdapter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 继成抽象类
 */
public class InterceptorM4 implements WebRequestInterceptor {

    private final Logger logger = LoggerFactory.getLogger(this.getClass().getCanonicalName());

    @Override
    public void preHandle(WebRequest request) throws Exception {
        logger.info("{}--{}:在请求处理之前进行调用（Controller方法调用之前）", this.getClass().getSimpleName(), Thread.currentThread().getStackTrace()[1].getMethodName());
    }

    @Override
    public void postHandle(WebRequest request, ModelMap model) throws Exception {
        logger.info("{}--{}:请求处理之后进行调用，但是在视图被渲染之前（Controller方法调用之后）", this.getClass().getSimpleName(), Thread.currentThread().getStackTrace()[1].getMethodName());
    }

    @Override
    public void afterCompletion(WebRequest request, Exception ex) throws Exception {
        logger.info("{}--{}:在整个请求结束之后被调用，也就是在DispatcherServlet 渲染了对应的视图之后执行（主要是用于进行资源清理工作）", this.getClass().getSimpleName(), Thread.currentThread().getStackTrace()[1].getMethodName());
    }

}
